package com.cheems.service.impl;

import com.cheems.dao.WallNewsMapper;
import com.cheems.entity.DTO.pageParamsDTO;
import com.cheems.entity.Pojo.wallNews;
import com.cheems.entity.Result.PageResult;
import com.cheems.service.WallNewsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WallNewsImpl implements WallNewsService {
    @Autowired
    private WallNewsMapper wallNewsMapper;
    /**
     * 首页信息列表分页查询
     * @param pageParamsDTO
     * @return
     */
    @Override
    public PageResult pageQuery(pageParamsDTO pageParamsDTO) {
        //开始分页查询
        //select * from 表 limit 0,10
        PageHelper.startPage(pageParamsDTO.getPageNum(),pageParamsDTO.getPageSize());
        //mapper返回对象
        Page<wallNews> page = wallNewsMapper.pageQuery(pageParamsDTO);
        //封装pageResult对象
        long total = page.getTotal();
        List<wallNews> result = page.getResult();

        return new PageResult(total,result);
    }
}
